package principale.presentation.gui.interfacciaGraficaPura;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import principale.main.Main;
import principale.presentation.gui.modelli.ModelloTabella;


public class RubricaInterfacciaGrafica extends JPanel implements ListSelectionListener{
	private static JFrame frame;
	private static final long serialVersionUID = 1L;
	private static JTable tabella;
	private static JPanel toolBarPane;
	private static ModelloTabella modelloTabella;

	public RubricaInterfacciaGrafica() {
		super(new BorderLayout());
		creaInterfaccia();
	}
	public void creaInterfaccia() {
		frame = new JFrame("Rubrica");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		creaTabella();
		creaMenu();
		creaToolBar();
	}
	
	protected void creaMenu() {
		Menu menu=new Menu();
		frame.setJMenuBar(menu.getMenuBar());
	}
	
	protected void creaToolBar() {
		ToolBar toolBar=new ToolBar();
		toolBarPane=toolBar.getToolBar();
		frame.add(toolBarPane,BorderLayout.PAGE_START);
	}
	
	protected void creaTabella() {
		modelloTabella=new ModelloTabella();
		modelloTabella.caricaRubrica();
		tabella = new JTable(modelloTabella);
		tabella.setPreferredScrollableViewportSize(new Dimension(1000, 400));
		tabella.setFillsViewportHeight(true);
		tabella.setSelectionMode(0); //Puoi solo scegliere una sola fila.
		JScrollPane listScrollPane = new JScrollPane(tabella);
		frame.add(listScrollPane, BorderLayout.CENTER);
	}
	
	protected void creaPanelloCerca() {
		PanelloCerca panelloCerca=new PanelloCerca();
		frame.add(panelloCerca.getPanello(),BorderLayout.PAGE_END);
	}
	public void mostraGUI() {
		frame.pack();
		Main.centralizzaFinestra(frame);
		frame.setVisible(true);
	}
	@Override
	public void valueChanged(ListSelectionEvent e) {
		// TODO Auto-generated method stub
	}

	public static void setButtonEnabled(int[] buttonID,boolean enabled) {
		for (int i: buttonID) {
			toolBarPane.getComponent(i).setEnabled(enabled);
		}
	}

	public static JTable getTabella() {
		return tabella;
	}

	public static ModelloTabella getModelloTabella() {
		return modelloTabella;
	}

	public static JFrame getFrame() {
		return frame;
	}
}
